package com.zyzg.config;

import com.zyzg.filter.AppAuthFilter;
import com.zyzg.filter.IpRateLimitFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 配置过滤器
 */
@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<AppAuthFilter> appAuthFilterRegistration(AppAuthFilter appAuthFilter) {
        FilterRegistrationBean<AppAuthFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(appAuthFilter);
        registration.addUrlPatterns("/api/*");
        registration.setName("appAuthFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean<IpRateLimitFilter> ipRateLimitFilterRegistration(IpRateLimitFilter ipRateLimitFilter) {
        FilterRegistrationBean<IpRateLimitFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(ipRateLimitFilter);
        registration.addUrlPatterns("/api/*");
        registration.setName("ipRateLimitFilter");
        registration.setOrder(2);
        return registration;
    }
}